// pages/checkInDetail/checkInDetail.js

//获取应用实例
const mdCode = require('../../utils/md5.js');
const desCode = require('../../utils/aesUtil.js');
const api_js = require("../../utils/api.js");
const util = require("../../utils/util.js");
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight,

    isIphoneX_: app.globalData.isIphoneX,

    // 活动报名Id
    customerid: '',
    // 二维码
    barcode: '',
    // 签到详情
    checkInDetail: [],

    Status: 1,
    barstatus: 0,
    nowDate: '',
    dataStatus: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {



    var that = this;
    this.setData({
      customerid: options.customerid,
      barcode: options.barcode,
      Status: app.globalData.Status,
      nowDate: new Date(),
    });



    let customerid = this.data.customerid;
    let barcode = this.data.barcode;



    var wMsgID = desCode.wMsgID();
    var wParam = desCode.to3des(`customerid=${customerid}_barcode=${barcode}`);
    var md = mdCode.hexMD5('9999' + '110' + wMsgID + wParam + 'q1w2e3r4t5y6');
    const data = {
      wAgent: 9999,
      wAction: 110,
      wMsgID: wMsgID,
      wParam: wParam,
      wSign: md,
      wImei: 222,
      wVersion: 2,
      wRequestUserID: 4
    }
    api_js.postReq(data, (res) => {
      console.log(res, "签到记录详情");



      this.setData({
        checkInDetail: res.Data[0],
        barstatus: res.Data[0].barstatus
      });
      console.log(this.data.barstatus, "app.globalData.Status");

      var Participantstime = res.Data[0].participantstime;
      var Termofvalidity = res.Data[0].termofvalidity;

      console.log(Participantstime, "Participantstime");
      console.log(Termofvalidity, "Termofvalidity");


      switch (this.data.barstatus) {
        case 0:
          /// 判断会议时间
          console.log(this.data.barstatus, "0");
          console.log(this.data.checkInDetail.participantstime)
          var NowTime = that.data.nowDate //当前时间
          this.tab(Participantstime, NowTime, Termofvalidity);
          break;
        case 1:
          ///判断按钮显示隐藏
          console.log(this.data.barstatus, "1");

          break;
        case 2:
          ///判断按钮显示隐藏

          console.log(this.data.barstatus, "2");

          break;
      }

    })





  },
  tab(date1, date2, date3) {

    console.log(21122)
    var that = this;
    // var oDate1 = util.formatTime(new Date(date1));
    // var oDate2 = util.formatDate(new Date(date2));
    var oDate1 = new Date(date1); //到访日期
    var oDate2 = new Date(date2); //当前时间
    var oDate3 = new Date(date3); //当前时间



    console.log(oDate1, 'oDate1');
    console.log(oDate2, 'oDate2');
    console.log(oDate3, 'oDate3');



    if (oDate1.getTime() <= oDate2.getTime()) {

      if (oDate3.getTime() <= oDate2.getTime()) {
        // 已失效
        that.setData({
          dataStatus: 1
        })
        console.log('活动已失效');
      } else {
        //进行中
        that.setData({
          dataStatus: 0
        })
        console.log('活动进行中');
      }
    } else if (oDate1.getTime() > oDate2.getTime()) {
      that.setData({
        dataStatus: 2
      })
      console.log('参会日期未到');
    } else {
      that.setData({
        dataStatus: 1
      })
    };


    console.log(that.data.dataStatus, "that.dataStatus哈哈哈");
  },

  checkedCommit() {




    var wMsgID = desCode.wMsgID();
    var wParam = desCode.to3des(`barcode=${this.data.barcode}`);
    var md = mdCode.hexMD5('9999' + '112' + wMsgID + wParam + 'q1w2e3r4t5y6');
    const data = {
      wAgent: 9999,
      wAction: 112,
      wMsgID: wMsgID,
      wParam: wParam,
      wSign: md,
      wImei: 222,
      wVersion: 2,
      wRequestUserID: 4
    }
    api_js.postReq(data, (res) => {
      console.log(res, "扫码签到");

      if (res.ReturnCode == 0) {

        let customerid = this.data.customerid;
        let barcode = this.data.barcode;



        var wMsgID = desCode.wMsgID();
        var wParam = desCode.to3des(`customerid=${customerid}_barcode=${barcode}`);
        var md = mdCode.hexMD5('9999' + '110' + wMsgID + wParam + 'q1w2e3r4t5y6');
        const data = {
          wAgent: 9999,
          wAction: 110,
          wMsgID: wMsgID,
          wParam: wParam,
          wSign: md,
          wImei: 222,
          wVersion: 2,
          wRequestUserID: 4
        }
        api_js.postReq(data, (res) => {
          console.log(res, "签到记录详情");

          this.setData({
            checkInDetail: res.Data[0],
            barstatus: res.Data[0].barstatus
          });

        })





      }


    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '媛月幸福汇',
      path: '/pages/index/index?isShare=1',
      imageUrl: '/images/DefaultAvatar.png',
    }
  },
})

//  barstatus == 0 && 当前时间小于等于 participantstime  barstatus == 0 && 展示参会日期未到  大于显示签到按钮，
//